<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="mall.demo.mybatis.pojo.Product" %>
<%@ page import="mall.demo.mybatis.pojo.ProductInCart" %>
<%@ page import="mall.demo.mybatis.pojo.User" %>
<%@ page import="mall.demo.mybatis.service.ProductService" %>
<%@ page import="mall.demo.util.SessionKeyEnum" %>
<%@ page import="java.util.List" %>
<%@ page import="java.util.ArrayList" %>
<!DOCTYPE html >
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<title>首页</title>
<link href="css/bootstrap.css" rel="stylesheet">

<script src="js/jquery.js?_=201703042022"></script>
<script src="js/bootstrap.js"></script>
<script src="js/index.js"></script>
</head>
<%
List<Product> products = (new ProductService()).getAllProducts();
Object obj = session.getAttribute(SessionKeyEnum.userObj.name());
boolean isUserLoggedIn = false;
if(obj != null) {
	isUserLoggedIn = true;
}
User userInfo = null;
if (isUserLoggedIn) {
	userInfo = (User)obj;
}

%>
<body>
<div class="container">
<jsp:include page="top.jsp"></jsp:include>
<!-- first div move down -->
<p style="height:50px;">&nbsp;</p>
<div class="row">

 	<% for (Product product : products) { %>
 	<div class="col-md-4">
 		<h2><%=product.getCode() %> - <%=product.getName() %></h2>
 		<p><%=product.getDescription() %></p>
 		<p><%=product.getPrice() %></p>
 		<% if (isUserLoggedIn) { %>
		<p><a href="#" onclick="addToCart(<%=product.getProductId() %>);">
			加入购物车</a></p>
		<% } else {%>
		
		<% } %>
	</div>
	<% } %>

<!-- </table> -->
</div>

<jsp:include page="footer.jsp"></jsp:include>
</div>
</body>
</html>